import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-05-23
 * Time: 17:13
 * 输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
 *利用递归
 *
 */
public class ReversePrint {
    public int[] reversePrint(ListNode head) {
        int[] arr=new int[0];
        if(head==null){
            return arr;
        }
        int[] ret=reversePrint(head.next);
        arr=Arrays.copyOf(ret,ret.length+1);
        arr[ret.length]=head.val;
        return arr;
    }
}
